package applet.login.components;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.LayoutManager;
import java.util.LinkedList;

import javax.swing.JPanel;

import data.CMSRes;

public class LoginBackground extends JPanel
{
	private static final long serialVersionUID = -1956252156183375154L;
	
	private Color mainColor;
	private LinkedList<DecorProfile> decor;
	
	public LoginBackground(LayoutManager layout)
	{
		super(layout);
		mainColor = CMSRes.Colors.get("Theme Color Light");
		decor = new LinkedList<DecorProfile>();
		decor.add(new DecorProfile("Decor 1", -373, 70, 1.0f, 0.0f));
		decor.add(new DecorProfile("Decor 2", 0, -207, 0.2f, 0.7f));
		decor.add(new DecorProfile("Decor 3", 0, -245, 0.0f, 1.0f));
		decor.add(new DecorProfile("Background Title", -517, -52, 1.0f, 1.0f));
	}
	
	public void paintComponent(Graphics g)
	{
		int w = getWidth();
		int h = getHeight();
		
		Graphics2D g2 = (Graphics2D) g;
		g2.setPaint(new GradientPaint(0, 0, Color.WHITE, w, h, mainColor));
		g2.fillRect(0, 0, w, h);
		g2.setPaint(Color.BLACK);
		
		for(DecorProfile d : decor)
			d.render(g, w, h);
	}
	
	private class DecorProfile
	{
		private Image image;
		private int offsetX;
		private int offsetY;
		private float locX;
		private float locY;
		
		public DecorProfile(String image, int oX, int oY, float lX, float lY)
		{
			this.image = CMSRes.Images.get(image);
			this.offsetX = oX;
			this.offsetY = oY;
			this.locX = lX;
			this.locY = lY;
		}
		
		public void render(Graphics g, int width, int height)
		{
			int x = (int) (width * locX) + offsetX;
			int y = (int) (height * locY) + offsetY;
			g.drawImage(image, x, y, null);
		}
	}
}